let details = document.querySelector("#Details");
let pl = document.querySelector("#pl")

function getUrlParams() {
    let href = location.href; //获取浏览器的地址
    let regExp = /.+\?(.+)/

    let param = regExp.exec(href) //匹配?后面的参数
    if (!param) {
        console.log('没有query参数');
        return
    }

    param = param[1]
        // console.log(param);
        // console.log(decodeURI(param));解码URI的参数编码
    let paramArr = param.split("&"); //多个参数以"&"切割 ?name=李雷&age=30
    // console.log(paramArr); //["name=李雷","age=30"]
    let query = {} //声明一个对象
    paramArr.forEach(item => {
        //['name','李雷']
        itemArr = item.split("=");
        // console.log(itemArr);
        query[itemArr[0]] = decodeURI(itemArr[1])
    })

    return query
}

let query = getUrlParams() //获取浏览器query参数 {product:10}



//发送ajax请求

fetch(`http://chst.vip:1234/api/getmoneyctrlproduct?productid=${query.productid}`)
    .then(body => body.json())
    .then(res => {
    console.log(res);
        let html = ""
        html = `
    <h2>${res.result[0].productName}</h2>
    <p>${res.result[0].productTime} ${res.result[0].productTips} </p>
    <div>
        ${res.result[0].productImgSm}
        <p>${res.result[0].productInfo}</p>
    </div>
    <p>${res.result[0].productInfo1}</p>
    ${res.result[0].productImgLg}
    ${res.result[0].productCity}
        `
        details.innerHTML = html
    })

fetch(`http://chst.vip:1234/api/getmoneyctrl`)
    .then(body => body.json())
    .then(res => {
        // console.log(res);
        let html = ""
        html = `
    ${res.result[0].productComment}`
        pl.innerHTML = html;
    })